package com.suning.sawp.po.companymem;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.suning.sawp.po.commodity.ConverterAdaptor;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;

@XStreamAlias("MbfBody")
@XStreamConverter(MdmCityInfo.class)
public class MdmCityInfo extends ConverterAdaptor {

    private static final Logger LOGGER = LoggerFactory.getLogger(MdmCityInfo.class);

    private List<MdmCity> data;

    public List<MdmCity> getData() {
        return this.data;
    }

    public void setData(List<MdmCity> data) {
        this.data = data;
    }

    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
        LOGGER.info("MdmCityInfo,{}", reader.toString());
        MdmCityInfo mdmCityInfo = new MdmCityInfo();
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            if ("T_ZMDIFS176".equals(reader.getNodeName())) {
                List<MdmCity> citys = new ArrayList<MdmCity>();
                while (reader.hasMoreChildren()) {
                    reader.moveDown();
                    if ("item".equals(reader.getNodeName())) {
                        MdmCity mdmCity = new MdmCity();
                        while (reader.hasMoreChildren()) {
                            reader.moveDown();
                            if ("REGIONAL_TRANSPORT_CODE".equals(reader.getNodeName())) {
                                mdmCity.setTransportCode(reader.getValue());
                            }
                            if ("REGIONAL_TRANSPORT_NAME".equals(reader.getNodeName())) {
                                mdmCity.setTransportName(reader.getValue());
                            }
                            if ("REGIONAL_TRANSPORT_LEVEL".equals(reader.getNodeName())) {
                                mdmCity.setTransportLevel(reader.getValue());
                            }
                            if ("PARENT_REGIONAL_TRANSPORT_CODE".equals(reader.getNodeName())) {
                                mdmCity.setRegionalTransportCode(reader.getValue());
                            }
                            reader.moveUp();
                        }
                        citys.add(mdmCity);
                    }
                    reader.moveUp();
                }
                mdmCityInfo.setData(citys);
            }
            reader.moveUp();
        }
        return mdmCityInfo;
    }
}
